<?php
namespace app\api\controller;
use app\common\BaseController;
use app\common\Net;
use app\api\model\QueryApply as QueryApplyModel;
class QueryApply extends BaseController{
    public function __construct(QueryApplyModel $queryApplyModel){
        parent::__construct();  
        $this->model = $queryApplyModel;
    }
    
    public function index(){
        $params = $this->request->param();
        $data = $this->model->allList($params);
        return $data;
    }

    public function get(){            
        $jsonArray=[
            "request"=>[
                "loginName"=> "LTSystem",
                "password"=> "i24ScojWQvoJlY4z+G8WwA==",
                "channelCode"=> "",
                "workNos"=> "GUZZ8348",
                "productCodes"=> "",
                "begdate"=> "2022-03-10",
                "enddate"=> "2022-03-20"
            ]
        ];

        $json = json_encode($jsonArray,JSON_UNESCAPED_UNICODE);
        
        $en_param = [
            'mode' => "1",
            'content' => $json
        ]; 
        $en_res = Net::http("http://cw.tsletu.com:9999/letu/api",$en_param,'POST');        
        $res = Net::http("https://sxthd-uat.cpic.com.cn/sxthd/cpic/queryApply ",$en_res,'POST');
        $de_param = [
            'mode' => "0",
            'content' => $res
        ]; 
        $de_res = Net::http("http://cw.tsletu.com:9999/letu/api",$de_param,'POST');
        $obj = json_decode($de_res,true);
        $data=$obj['response'];
        if($data['returnNumber']=="0000000000"){
            $param=[
                "begdate"=>$jsonArray['request']['begdate'],
                "enddate"=>$jsonArray['request']['enddate'],
                "settleNo"=>$data['settleNo'],
                "stat" => 3
            ];
            $this->model->allowField(true)->isUpdate(false)->save($param);
            echo "true";
        }else{
            echo "false";
        }        
    }

    public function create(){   
        $params = $this->request->param();         
        $jsonArray=[
            "request"=>[
                "loginName"=> "LETU",
                "password"=> "Y/veTqvxj7UQ9IDCBBlqdA==",
                "channelCode"=> "",
                "workNos"=> "GUZZ8348",
                "productCodes"=> "",
                "begdate"=> $params['begdate'],
                "enddate"=> $params['enddate']
            ]
        ];

        $json = json_encode($jsonArray,JSON_UNESCAPED_UNICODE);
        
        $en_param = [
            'mode' => "1",
            'content' => $json,
            'key'=>"auvY+v+HjNMmlvrR+k6CMD=="
        ]; 
        $en_res = Net::http("http://cw.tsletu.com:9999/letu/api",$en_param,'POST');        
        $res = Net::http("https://sxthd.cpic.com.cn/sxthd/cpic/queryApply ",$en_res,'POST');
        $de_param = [
            'mode' => "0",
            'content' => $res,
            'key'=>"auvY+v+HjNMmlvrR+k6CMD=="
        ]; 
        $de_res = Net::http("http://cw.tsletu.com:9999/letu/api",$de_param,'POST');
        echo $de_res;
        $obj = json_decode($de_res,true);
        
        $data=$obj['response'];
        if($data['returnNumber']=="0000000000"){
            $param=[
                "begdate"=>$params['begdate'],
                "enddate"=>$params['enddate'],
                "settleNo"=>$data['settleNo'],
                "stat" => 3
            ];
            $this->model->allowField(true)->isUpdate(false)->save($param);
            
        }
        var_dump($data);     
    }

}
